<?php
// +----------------------------------------------------------------------
// | Fanwe 方维订餐小秘书商业系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 云淡风轻(88522820@qq.com)
// +----------------------------------------------------------------------

class pmenuModule extends StoreBaseModule
{
	public function index(){
		$store_info = $GLOBALS['db']->getRowCached("select name from ".DB_PREFIX."supplier_location where id = ".intval($_REQUEST['sid'])." and is_effect = 1");
		if(!$store_info)
			exit();
		$mid = intval($_REQUEST['mid']);
		if($mid > 0){
			$menu = $GLOBALS['db']->getOne("SELECT cache_data FROM ".DB_PREFIX."user_fav_menu WHERE id=".intval($_REQUEST['mid'])." AND user_id=".intval($GLOBALS['user_info']['id']));
			if($menu)
				$menu = unserialize($menu);
		}
		
		$templist = $GLOBALS['db']->getAllCached("SELECT id,name,price,is_special,cate_id FROM ".DB_PREFIX."supplier_location_menu WHERE supplier_location_id=".intval($_REQUEST['sid'])." ORDER BY id DESC");
		
		$list = array();
		$special_num = 0;
		$normal_num = 0;
		$all_price = 0;
		$cate = array();
		
		foreach($templist as $k=>$v){
			$nums = 0;
			if($mid > 0){
				foreach($menu as $kk=>$vv)
				{
					if($vv['id']==$v['id']){
						$nums = $vv['nums'];
					}
				}
			}
			else{
				$nums = es_session::get("cho_nums_".$v['id']);
			}
			
			if(intval($nums) > 0){
				$templist[$k]['nums'] = $nums;
				if($v['is_special']){
					$special_num +=1;
				}
				else{
					$normal_num +=1;
				}
				$list[]=$templist[$k];
				$all_price +=$v['price']*$nums;
				$cate[$v['cate_id']] =  $v['cate_id'];
			}
		}
		
		$GLOBALS['tmpl']->assign("store_info",$store_info);
		$GLOBALS['tmpl']->assign("special_num",$special_num);
		$GLOBALS['tmpl']->assign("normal_num",$normal_num);
		$GLOBALS['tmpl']->assign("all_price",$all_price);
		$GLOBALS['tmpl']->assign("all_num",$special_num + $normal_num);
		$GLOBALS['tmpl']->assign("all_cate",count($cate));
		$GLOBALS['tmpl']->assign("list",$list);
		$GLOBALS['tmpl']->display("store_menu_print.html");
	}
}
?>